<!--
 * @Author: yl
 * @Date: 2024-04-09 16:07:23
 * @LastEditTime: 2024-04-09 16:07:23
 * @LastEditors: Please set LastEditors
 * @Description: 养殖品种页面
-->
<template>
  <BaseMainSlot :show-tab="false" :btn-box="false" :show-search-box="true">
    <template v-slot:btn-box>
      <!-- <ActionBar
        :page-no="249"
        :add-active="addActive"
        :del-active="delActive"
        :edit-active="editActive"
        :has-edit="false"
        :has-save="false"
        @add="add"
        @edit="edit"
        @del="del"
      /> -->
    </template>
    <template v-slot:search-box>
      <SearchBox :renovate="true" @search="search">
        <div class="common-search-item">
          <div class="label"></div>
          <div class="input"></div>
        </div>
      </SearchBox>
    </template>
    <template v-slot:table-box>
      <el-table
        ref="tableData"
        v-loading="loading"
        highlight-current-row
        :data="tableData"
        stripe
        border
        height="92%"
      >
        <el-table-column type="index" label="序号" width="60" />
        <el-table-column
          v-for="item, index in tableDataList"
          :key="index"
          :type="`${item.porp}`"
          :prop="`${item.porp}`"
          :label="item.name"
          :min-width="item.porp==='eleEarLabel'? '200': '130'"
          :column-key="`${item.porp}`"
        >
          <template #header>
            <TypePopover
              v-if="tableUpStauts === 1"
              :column-index="index"
              :column="item"
              :filter-options="item.typeObj.list"
              :table-up-stauts="tableUpStauts"
              @tableUpdate="tableUpdate($event, item.name)"
            />
          </template>
        </el-table-column>
      </el-table>
      <Pagination
        :page-size="pageSize"
        :current-page="currentPage"
        :total-size="totalSize"
        @changePageSize="changePageSize"
        @changeCurrentPage="changeCurrentPage"
      />
    </template>
  </BaseMainSlot>
</template>

<script>
// import ActionBar from "@/components/ActionBar";
import SearchBox from "@/components/SearchBox";
import { mymixin } from "@/utils/mixins";
import TypePopover from "@/components/ZnFilterTable/typePopover.vue";

import scanRecordApi from "@/api/trace-source-web/tracing-source-code/scan-code-record";
export default {
  name: "SheepInformation",
  components: {
    // ActionBar,
    SearchBox,
    TypePopover
  },
  mixins: [mymixin],
  data() {
    return {
      obj: {
        name: ""
      },
      breedTypeName: "",
      // 员工姓名
      breedTypeNo: "",
      // 选中的数据项数组 employeeId组成 (此数组最多为一个)
      selectedStaffList: [],
      upLoading: false,
      downLoading: false,
      formData: {
        person: {}
      },
      facilityList: [],
      facilityLists: [],
      tableDataList: [
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "tracingSourceCodeNo",
          typeObj: {},
          name: "溯源编号",
          required: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "address",
          typeObj: {},
          name: "扫码地点",
          required: true
        },
        {
          type: "input", // input Select Checkbox TimePicker
          porp: "ip",
          typeObj: {},
          name: "ip地址",
          required: true
        },
        {
          type: "datetime_range", // input Select Checkbox TimePicker
          porp: "scanTime",
          typeObj: {
            list: ['startTime', 'endTime']
          },
          name: "扫码时间",
          required: true
        }
      ],
      searchObj: {}
    };
  },
  created() {
  },
  mounted() {
    // 查询部门
    // 获取表格数据
    this.search();
  },
  methods: {
    tableUpdatePlus(data) {
      // 日期范围查询
      if (data.columnType === 'datetime_range') {
        this.$set(this.searchObj, data['typeObj']['list'][0], data.value && data.value[0]);
        this.$set(this.searchObj, data['typeObj']['list'][1], data.value && data.value[1]);
        this.searchObj.scanTime && delete this.searchObj.scanTime;
        if (data.type === "Reset") {
          for (let key in this.searchObj) {
            if (key === data['typeObj']['list'][0] || key === data['typeObj']['list'][1]) {
              this.$set(this.searchObj, key, undefined);
            }
          }
        }
      }
    },
    getTableDataList() {
      this.loading = true;
      let params = {
        page: this.currentPage,
        size: this.pageSize,
        entity: { ...this.searchObj }
      };
      scanRecordApi.queryPageByCondition(params).then((res) => {
        this.loading = false;
        let data = res.data;
        // 赋值总条数
        if (data) {
          this.totalSize = data.totalElements;
          // 赋值数组
          this.tableData = JSON.parse(
            this.livestock(JSON.stringify(data.content))
          );
          // console.log(this.tableData)
          this.addblankmet();
          this.resetActionBar();
        }
      });
    }
  }
};
</script>

<style scoped lang="scss">
@import "~@/styles/variables.scss";
</style>
